<?php 
include __DIR__ . "/../vendor/PHPMailer/PHPMailerAutoload.php";

error_reporting(0);

define("BH_EMAIL","petformanceveterinary@gmail.com");
define("BH_PASSWORD","kawitcavite ");

define("DB_HOST", trim ("mysql.hostinger.ph"));
define("DB_NAME", trim ("u117875672_db"));
define("DB_USERNAME", trim ("u117875672_pet"));
define("DB_PASSWORD", trim ("okslrri059415"));

$con = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
if(!$con){
	die("mysql connection failed". mysql_error());
}

$select_db = mysql_select_db(DB_NAME, $con);
if(!$select_db){
	die("mysql selection failed". mysql_error());
}


//sendEmail("pawwpresco@gmail.com","gagu","From Petformance");

function getEmail($user_id)
{
	$con = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
	$sql="SELECT * FROM user_db WHERE User_ID = '{$user_id}'";

	$list = mysql_query($sql,$con);	
	
	$email = '';
	while($row=mysql_fetch_array($list))
	{								 
		$email = $row['Email_Address'];
	}
	return $email;
}

function sendEmail($to,$message,$subject)
    {
    	ini_set("SMTP","ssl://smtp.gmail.com"); 
		ini_set("smtp_port","465"); //No further need to edit your configuration files.
		$mail = new PHPMailer();
		//$mail->SMTPDebug = 1;
		$mail->SMTPAuth = true;
		$mail->Host = "smtp.gmail.com"; // SMTP server
		$mail->SMTPSecure = "ssl";
		$mail->Username = BH_EMAIL; //account with which you want to send mail. Or use this account. i dont care :-P
		$mail->Password = BH_PASSWORD; //this account's password.
		$mail->Port = "465";
		$mail->IsSMTP();  // telling the class to use SMTP
		$mail->isHTML(true);
		$rec1="trials.php@gmail.com"; //receiver. email addresses to which u want to send the mail.
		$rec2=$to;
		$mail->AddAddress($rec2);
		$mail->Subject  = $subject;
		$mail->Body     = $message;
		$mail->setFrom(BH_EMAIL,"Petformance.ph");

		$mail->WordWrap = 200;
		//var_dump(!$mail->Send()); die;
		if(!$mail->Send())
		{
		  return $mail->ErrorInfo;
		}
		else
		{
	 	  return true;
		}
    }
?>
